home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4722 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.5 KB  |  56 lines

  1. Path: news2.ios.com!usenet
  2. From: vlad@gramercy.ios.com (Vlastimil Adamovsky)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Problem:  Passing pointer to function to Template Member function
  5. Date: Wed, 31 Jan 1996 21:14:51 GMT
  6. Organization: Internet Online Services
  7. Message-ID: <4eolj8$1fl@news2.ios.com>
  8. References: <391851586wnr@parkbayl.demon.co.uk>
  9. NNTP-Posting-Host: ppp-33.ts-7.hck.idt.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Martin Bayly <martin@parkbayl.demon.co.uk> wrote:
  13.  
  14. >I have a parameterized list class.  I would like one of the list class member functions to iterate
  15. >the list and for each object, call one of the object's own member functions.  Thus my class is 
  16. >defined as:
  17.  
  18. >template <class T>
  19. >class List
  20. >{
  21. >public:
  22. >    List( );
  23. >    ~List( );
  24. >    // other functions
  25. >>    void Iterate(void (T::*pFunc)( ) );
  26. >private:
  27. >    Node<T> itsHead;
  28. >    ULONG itsCount;
  29. >};
  30.  
  31. >i.e. I'm trying to define Iterate to take a pointer to a function of the object T, whatever T happens 
  32. >to be.  I get the following two compile errors (Visual C++ V4.0):
  33.  
  34. All compilers are equal. But some of them are more equal than the
  35. others. That's why try this:
  36.  
  37. template <class T>
  38. class List
  39. {
  40. public:
  41.             typedef void (T::*PFUNC)( );
  42.     List( ) {}
  43.     ~List( ) {}
  44.     // other functions
  45.     void Iterate(PFUNC){}
  46. private:
  47.     Node<T> itsHead;
  48.     ULONG itsCount;
  49. };
  50.  
  51. *******************************************
  52. *    Vlastimil Adamovsky                  *
  53. * Smalltalk, C++ and Envelop development  *
  54. *******************************************
  55.  
  56.